var pageSize=5,pageNum=1,pageTotal=0;
var pageSize2=5,pageNum2=1,pageTotal2=0;
var pageSize3=6,pageNum3=1,pageTotal3=0;
$(function(){
	loadQueryBasic_id();
	
	loadQueryRec_newsBybasic_id();
	
	loadDeliver_resumeMessage();
	
});

function loadQueryBasic_id(){
	utilAjax("/adminBasic/queryBasic_id","pageNum="+pageNum+"&pageSize="+pageSize,"post",
			function(data){
		pageNum = data.pageNum;
		pageSize = data.pageSize;
		pageTotal = data.pages;
		parseQueryBasic_id(data.list);
	});
}
function parseQueryBasic_id(lists){
	var basicCon = "";
	if(lists!=""){
		basicCon +="<tr class='info text-info'><th height='40'>管理员</th><th>信息内容</th><th>信息状态</th><th>操作</th></tr>";
		$.each(lists,function(i,b){
			basicCon +="<tr>" +
						"<td height='40'>"+b.admin_id+"号管理员</td>" +
						"<td><textarea readonly='readonly' class='form-control' rows='3'>"+b.adminRec_news_context+"</textarea></td>"+
						"<td>"+(b.adminRec_news_status==1?"未读":"已读")+"</td>"+
						"<td>" +
							"<input type='button' value='已读' onclick='updateAdminBasicAdminRec_news_status("+b.adminBasic_news_id+",2)' class='btn btn-primary'> " +
							"<input type='button' value='删除' onclick='updateAdminBasicAdminRec_news_status("+b.adminBasic_news_id+",3)' class='btn btn-primary'> " +
						"</td>" +
					"</tr>";
		});
		basicCon+= "<tr><td colspan='4' height='40' align='center'>当前页:"+pageNum+"/总页数:"+pageTotal+"</td></tr>";
		basicCon+= "<tr>" +
				"<td colspan='4' align='center'>" +
				"<input type='button' value='首页' onclick=changeQueryBasicPage(this) class='btn btn-primary'> " +
				"<input type='button' value='上一页' onclick=changeQueryBasicPage(this) class='btn btn-primary'> " +
				"<input type='button' value='下一页' onclick=changeQueryBasicPage(this) class='btn btn-primary'> " +
				"<input type='button' value='末页' onclick=changeQueryBasicPage(this) class='btn btn-primary'> " +
			"</td></tr>";
	}else{
		basicCon+= "<tr><td align='center'><font size='5' color='red'>暂无消息</font></td></tr>";
	}
	$("#adminBasicTable").html(basicCon);
}
function changeQueryBasicPage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum=1;
		loadQueryBasic_id();
		break;
	case "上一页":
		if(pageNum>1){
			pageNum--;
			loadQueryBasic_id();
		}	
		break;
	case "下一页":
		if(pageNum<pageTotal){
			pageNum++;
			loadQueryBasic_id();
		}
		break;
	case "末页":
		pageNum=pageTotal;
		loadQueryBasic_id();
		break;
	}
}
function updateAdminBasicAdminRec_news_status(adminBasic_news_id,adminRec_news_status){
	utilAjax("/adminBasic/updateAdminBasicAdminRec_news_status","adminBasic_news_id="+adminBasic_news_id+"&adminRec_news_status="+adminRec_news_status,"post",
			function(flag){
		var flagCon = flag?"操作成功":"操作失败";
		if(flag){
			loadQueryBasic_id();
		}
		$("#alterContent").text(flagCon);
		loadAlter();
	});
}

function loadQueryRec_newsBybasic_id(){
	utilAjax("/rec_news/queryRec_newsBybasic_id","pageNum="+pageNum2+"&pageSize="+pageSize2,"post",
			function(data){
		pageNum2 = data.pageNum;
		pageSize2 = data.pageSize;
		pageTotal2 = data.pages;
		parseQueryRec_newsBybasic_id(data.list);
	});
}
function parseQueryRec_newsBybasic_id(lists){
	var newsCon = "";
	if(lists!=""){
		newsCon +="<tr class='info text-info'><th height='40'>招聘者</th><th>信息内容</th><th>信息状态</th><th>操作</th></tr>";
		$.each(lists,function(i,b){
			newsCon +="<tr>" +
						"<td height='40'>"+b.recBasic.recruiter_name+"</td>" +
						"<td><textarea readonly='readonly' class='form-control' rows='3'>"+b.rec_news_context+"</textarea></td>"+
						"<td>"+(b.rec_news_visit_state==1?"未读":"已读")+"</td>"+
						"<td>" +
							"<input type='button' value='已读' onclick='updateRec_news_visit_state("+b.rec_news_id+",2)' class='btn btn-primary'> " +
							"<input type='button' value='删除' onclick='updateRec_news_visit_state("+b.rec_news_id+",3)' class='btn btn-primary'> " +
						"</td>" +
					"</tr>";
		});
		newsCon+= "<tr><td colspan='4' height='40' align='center'>当前页:"+pageNum2+"/总页数:"+pageTotal2+"</td></tr>";
		newsCon+= "<tr>" +
				"<td colspan='4' align='center'>" +
				"<input type='button' value='首页' onclick=changeQueryRec_newsBybasic_idPage(this) class='btn btn-primary'> " +
				"<input type='button' value='上一页' onclick=changeQueryRec_newsBybasic_idPage(this) class='btn btn-primary'> " +
				"<input type='button' value='下一页' onclick=changeQueryRec_newsBybasic_idPage(this) class='btn btn-primary'> " +
				"<input type='button' value='末页' onclick=changeQueryRec_newsBybasic_idPage(this) class='btn btn-primary'> " +
			"</td></tr>";
	}else{
		newsCon+= "<tr><td align='center'><font size='5' color='red'>暂无消息</font></td></tr>";
	}
	$("#rec_newsTable").html(newsCon);
}
function changeQueryRec_newsBybasic_idPage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum2=1;
		loadQueryRec_newsBybasic_id();
		break;
	case "上一页":
		if(pageNum2>1){
			pageNum2--;
			loadQueryRec_newsBybasic_id();
		}	
		break;
	case "下一页":
		if(pageNum2<pageTotal2){
			pageNum2++;
			loadQueryRec_newsBybasic_id();
		}
		break;
	case "末页":
		pageNum2=pageTotal2;
		loadQueryRec_newsBybasic_id();
		break;
	}
}
function updateRec_news_visit_state(rec_news_id, rec_news_visit_state){
	utilAjax("/rec_news/updateRec_news_visit_state","rec_news_id="+rec_news_id+"&rec_news_visit_state="+rec_news_visit_state,"post",
			function(flag){
		var flagCon = flag?"操作成功":"";
		if(flag){
			loadQueryRec_newsBybasic_id();
			$("#alterContent").text(flagCon);
			loadAlter();
		}
		
	});
}


function loadDeliver_resumeMessage(){
	
	utilAjax("/deliver_resume/queryDeliver_resumeByDoc_id","pageNum="+pageNum3+"&pageSize="+pageSize3,"post",
			function(data){
		pageNum3 = data.pageNum;
		pageSize3 = data.pageSize;
		pageTotal3 = data.pages;
		parseDeliver_resumeMessage(data.list);
	});
}

function parseDeliver_resumeMessage(lists){
	var deliverCon = "";
	if(lists!=""){
		deliverCon +="<tr class='info text-info'><th height='40'>招聘人</th><th>招聘岗位</th><th>面试状态</th><th>操作</th></tr>";
		$.each(lists,function(i,b){
			var dr_state = "";
			var goBut = "";
			if(b.dr_state==1){dr_state="简历申请未通过"}
			if(b.dr_state==2){
				//申请通过提供选择机会
				dr_state="简历申请通过";
				goBut = "<input type='button' onclick='updateDr_download_state("+b.dr_id+",2)' value='接受面试邀请' class='btn btn-primary'> ";
				goBut += " <input type='button' onclick='updateDr_delete_state("+b.dr_id+",2)' value='拒绝面试邀请' class='btn btn-primary'>";
			}
			if(b.dr_state==3){dr_state="审核中"}
			var delBut = "";
			if(b.dr_state!=2){delBut = "";}
			if(b.dr_download_state==2){goBut="";}//同意面试，取消选择机会
			deliverCon +="<tr>" +
						"<td width='100' height='40'>"+b.basic.recruiter_name+"</td>" +
						"<td width='200'>"+b.rec_title+"</td>"+
						"<td width='245'><textarea readonly='readonly' class='form-control' rows='3'>"+dr_state+"</textarea></td>"+
						"<td>"+goBut+" " +
						"<input type='button' value='删除' onclick='updateDr_delete_state("+b.dr_id+",2)' class='btn btn-primary'>" +
						"</td>" +
					"</tr>";
		});
		deliverCon+= "<tr><td colspan='4' height='40' align='center'>当前页:"+pageNum3+"/总页数:"+pageTotal3+"</td></tr>";
		deliverCon+= "<tr>" +
				"<td colspan='4' align='center'>" +
				"<input type='button' value='首页' onclick=changeDeliver_resumeMessage(this) class='btn btn-primary'> " +
				"<input type='button' value='上一页' onclick=changeDeliver_resumeMessage(this) class='btn btn-primary'> " +
				"<input type='button' value='下一页' onclick=changeDeliver_resumeMessage(this) class='btn btn-primary'> " +
				"<input type='button' value='末页' onclick=changeDeliver_resumeMessage(this) class='btn btn-primary'> " +
			"</td></tr>";
	}else{
		deliverCon+= "<tr><td align='center'><font size='5' color='red'>暂无消息</font></td></tr>";
	}
	$("#deliver_resumeTable").html(deliverCon);
}
function backUp(){
	$("#deliver_resumeTable").hide();
	$("#rec_newsTable").show();
}

function updateDr_delete_state(dr_id, dr_delete_state){
	utilAjax("/deliver_resume/updateDr_delete_state","dr_id="+dr_id+"&dr_delete_state="+dr_delete_state,"post",
			function(flag){
		var flagCon = flag?"操作成功":"";
		if(flag){
			loadDeliver_resumeMessage();
			$("#alterContent").text(flagCon);
			loadAlter();
		}
		
	});
}
function updateDr_download_state(dr_id,dr_download_state){
	utilAjax("/deliver_resume/updateDr_download_state","dr_id="+dr_id+"&dr_download_state="+dr_download_state,"post",
			function(flag){
		var flagCon = flag?"操作成功":"";
		if(flag){
			loadDeliver_resumeMessage();
			$("#alterContent").text(flagCon);
			loadAlter();
		}
		
	});
}

function changeDeliver_resumeMessage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum3=1;
		showDeliver_resumeTable();
		break;
	case "上一页":
		if(pageNum3>1){
			pageNum3--;
			showDeliver_resumeTable();
		}	
		break;
	case "下一页":
		if(pageNum3<pageTotal3){
			pageNum3++;
			showDeliver_resumeTable();
		}
		break;
	case "末页":
		pageNum3=pageTotal3;
		showDeliver_resumeTable();
		break;
	}
}

function loadAlter(){
	var alterCon = $("#alterContent").text();
	if(alterCon!=""){
		$(".alterDiv").show();
		var interval = setInterval(function(){
			$(".alterDiv").hide();
			$("#alterContent").text("");
			clearInterval(interval);
		},3000);
	}
}

function utilAjax(url,data,type,success){
	$.ajax({
		url:url,
		data:data,
		dataType:'json',
		type:type,
		success:success,
		error:function(){
		}
	});
}